package com.restaurant.springboot.controller;

import com.restaurant.springboot.entity.DishesSeriesEntity;
import com.restaurant.springboot.service.DishesSeriesService;
import com.restaurant.springboot.utils.RespCode;
import com.restaurant.springboot.utils.RespEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/admin/dishesSeries")
public class AdminDishesSeriesController {


    @Autowired
    private DishesSeriesService dishesSeriesService;


    /**
     * 新增新菜品类
     * @param dishesSeries
     * @return
     */
    @PostMapping()
    public RespEntity addDishesSeries(@RequestBody DishesSeriesEntity dishesSeries){
        if(dishesSeriesService.saveDishesSeries(dishesSeries)){
            return new RespEntity(RespCode.SUCCESS);
        }else{
            return new RespEntity(RespCode.ERROR, "新增菜品类时发生错误", null);
        }
    }

    /**
     * 删除菜品类
     * @param dishesSeriesId
     * @return
     */
    @DeleteMapping("{dishesSeriesId}")
    public RespEntity deleteDishesSeries(@PathVariable int dishesSeriesId){
        try {
            DishesSeriesEntity dishesSeries = dishesSeriesService.getDishesSeriesById(dishesSeriesId);
            dishesSeriesService.deleteDishesSeries(dishesSeries);
            return new RespEntity(RespCode.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new RespEntity(RespCode.ERROR, "删除菜品类时发生错误", null);
        }
    }


}
